package cn.wolfcode.luowowo.search.service.impl;

import cn.wolfcode.luowowo.search.repository.IDestinationTemplateRepository;
import cn.wolfcode.luowowo.search.service.IDestinationSearchService;
import cn.wolfcode.luowowo.search.template1.DestinationTemplate;
import com.alibaba.dubbo.config.annotation.Service;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;

/**
 * Created by Administrator on 2019/7/15.
 */
@Service
public class DestinationSearchServiceImpl implements IDestinationSearchService{
    @Autowired
    private ElasticsearchTemplate template;
    @Autowired
    private IDestinationTemplateRepository dao;
    @Autowired
    private TransportClient client;

    @Override
    public void creatIndex() {
        template.createIndex(DestinationTemplate.class);
        template.getMapping(DestinationTemplate.class);
    }

    @Override
    public void save(DestinationTemplate template) {
        dao.save(template);
    }

    @Override
    public DestinationTemplate queryDestByName(String name) {
        Iterable<DestinationTemplate> dests = dao.search(QueryBuilders.termQuery("name", name));
        DestinationTemplate dest = dests.iterator().next();
        return dest;
    }
}
